package o;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import okhttp3.RealCall;
import okhttp3.RealCall.d;

public class ful extends ftv {
    static final /* synthetic */ boolean ᐝ = (!ful.class.desiredAssertionStatus());
    protected final Deque<RealCall> ʻ = new ArrayDeque();
    private int ʽ = 5;
    protected final Deque<d> ˊ = new ArrayDeque();
    protected int ˋ = 64;
    @Nullable
    protected ExecutorService ˎ;
    @Nullable
    protected Runnable ˏ;
    protected final Deque<d> ॱ = new ArrayDeque();

    public synchronized ExecutorService ˋ() {
        if (this.ˎ == null) {
            this.ˎ = new ThreadPoolExecutor(0, ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED, 60, TimeUnit.SECONDS, new SynchronousQueue(), fvg.ˊ("OkHttp Dispatcher", false));
        }
        return this.ˎ;
    }

    public void ˋ(int i) {
        if (i < 1) {
            throw new IllegalArgumentException("max < 1: " + i);
        }
        synchronized (this) {
            this.ˋ = i;
        }
        ˏ();
    }

    public void ॱ(d dVar) {
        synchronized (this) {
            this.ॱ.add(dVar);
        }
        ˏ();
    }

    private boolean ˏ() {
        int i = 0;
        if (ᐝ || !Thread.holdsLock(this)) {
            boolean z;
            List arrayList = new ArrayList();
            synchronized (this) {
                Iterator it = this.ॱ.iterator();
                while (it.hasNext()) {
                    d dVar = (d) it.next();
                    if (this.ˊ.size() >= this.ˋ) {
                        break;
                    } else if (ˋ(dVar) < this.ʽ) {
                        it.remove();
                        arrayList.add(dVar);
                        this.ˊ.add(dVar);
                    }
                }
                if (ॱ() > 0) {
                    z = true;
                } else {
                    z = false;
                }
            }
            int size = arrayList.size();
            while (i < size) {
                ((d) arrayList.get(i)).ॱ(ˋ());
                i++;
            }
            return z;
        }
        throw new AssertionError();
    }

    protected int ˋ(d dVar) {
        int i = 0;
        for (d dVar2 : this.ˊ) {
            if (!dVar2.ॱ().forWebSocket) {
                int i2;
                if (dVar2.ˊ().equals(dVar.ˊ())) {
                    i2 = i + 1;
                } else {
                    i2 = i;
                }
                i = i2;
            }
        }
        return i;
    }

    public synchronized void ˊ(RealCall realCall) {
        this.ʻ.add(realCall);
    }

    public void ˎ(d dVar) {
        ॱ(this.ˊ, dVar);
    }

    public void ˎ(RealCall realCall) {
        ॱ(this.ʻ, realCall);
    }

    private <T> void ॱ(Deque<T> deque, T t) {
        synchronized (this) {
            if (deque.remove(t)) {
                Runnable runnable = this.ˏ;
            } else {
                throw new AssertionError("Call wasn't in-flight!");
            }
        }
        if (!ˏ() && runnable != null) {
            runnable.run();
        }
    }

    public synchronized int ॱ() {
        return this.ˊ.size() + this.ʻ.size();
    }

    public int ˊ() {
        return 1;
    }

    void ˎ(String str, int i, String str2) {
    }

    void ˊ(String str, int i, String str2) {
    }
}
